<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms gv-forms-fluid" layout="column">
  <h1>User Fields</h1>
  <div class="gv-form">
    <h2></h2>
    <div class="gv-form-content" layout="column">
      <md-table-container>
        <table md-table class="gv-table-dense" ng-init="customField = 'key'">
          <thead md-head md-order="customField">
            <tr md-row>
              <th md-column md-order-by="key">Key</th>
              <th md-column md-order-by="label">Label</th>
              <th md-column md-order-by="required">Required</th>
              <th md-column>Values</th>
              <th md-column width="64px" nowrap ng-if="$ctrl.canDelete"></th>
            </tr>
          </thead>
          <tbody md-body>
            <tr md-row ng-repeat="field in $ctrl.fields | orderBy: customField">
              <td md-cell>
                <a ng-if="$ctrl.canUpdate" ng-click="$ctrl.updateField(field)">{{field.key}}</a>
                <span ng-if="!$ctrl.canUpdate">{{field.key}}</span>
              </td>
              <td md-cell>{{field.label}}</td>
              <td md-cell><md-checkbox ng-checked="field.required" disabled /></td>
              <td md-cell>
                <div style="line-height: 20px" ng-repeat="value in field.values">{{value}}</div>
              </td>
              <td md-cell ng-if="$ctrl.canDelete">
                <div layout="row" layout-align="end end">
                  <ng-md-icon
                    icon="delete"
                    ng-click="$ctrl.deleteField(field)"
                    style="font-size: 24px; height: 24px"
                    ng-if="$ctrl.fieldDeletable(field)"
                  >
                    <md-tooltip md-direction="top" md-visible="false">Delete User Field</md-tooltip>
                  </ng-md-icon>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </md-table-container>
    </div>
  </div>
</div>

<md-button
  ng-if="$ctrl.canCreate"
  aria-label="Add User Field"
  class="md-fab md-fab-bottom-right md-fab-scrollable"
  ng-class="{'gv-help-displayed': $ctrl.$rootScope.helpDisplayed}"
  ng-click="$ctrl.newField()"
>
  <md-tooltip md-direction="top" md-visible="false">Add a new user field</md-tooltip>
  <ng-md-icon icon="add"></ng-md-icon>
</md-button>
